-module(tester).
%-compile([native]).
-export([test/1, test_all/0]).

test_compare(A,B) when A==B -> ok;
test_compare(_,_) -> error.

test_compare_strip(A,B,Input) ->
    case test_compare(A,B) of
        ok -> ok;
        error -> {error, Input, A, B}
    end.

test(Cases) ->
    test(1, Cases).

test(Num, [{F,Input,Expected}|Cases]) ->
    Res = (catch test_compare_strip(F(Input),Expected,Input)),
    [{Num, Res}] ++ test(Num+1, Cases);
test(Num, [{Name, F,Input,Expected}|Cases]) ->
    Res = (catch test_compare_strip(F(Input),Expected,Input)),
    [{Name, Res}] ++ test(Num+1, Cases);
test(_, []) -> [].

test_all() ->
    io:format("Scanner: ~p~nParser: ~p~nVars: ~p~nEnvironment: ~p~nRunner: ~p~nErlol ~p~n",
        [
            scanner:test(),
            parser:test(),
            vars:test(),
            environment:test(),
            runner:test(),
            erlol:test()
        ]).

